/**
 * @author LKQ
 * @date 2022/2/22 21:30
 * @description
 */
public class FormalSolution2 {
    public static void main(String[] args) {

    }
    public void flatten(TreeNode root) {
        TreeNode curr = root;
        while (curr != null) {
            if (curr.left != null) {
                TreeNode next = curr.left;
                TreeNode predecessor = next;
                while (predecessor.right != null) {
                    predecessor = predecessor.right;
                }
                // 最精髓一笔，将cur的整个右子节点移动到左子树第一层的右节点
                predecessor.right = curr.right;
                curr.left = null;
                curr.right = next;
            }
            curr = curr.right;
        }
    }
}
